home *** CD-ROM | disk | FTP | other *** search
- #ifndef __ALBUM__
- #include "Album.h"
- #endif
-
- #ifndef __OCETEMPLATES__
- #include <OCETemplates.h>
- #endif
-
- #ifndef __TRACK__
- #include "Track.h"
- #endif
-
- static OSErr DoIdle(DETCallBlockPtr callBlockPtr);
-
- pascal OSErr AlbumCode(DETCallBlockPtr callBlockPtr)
- {
- OSErr err = 1;
-
- if ((callBlockPtr->protoCall.reqFunction < kDETcmdTargetedCall) || (callBlockPtr->protoCall.target.selector == kDETSelf))
- {
- switch (callBlockPtr->protoCall.reqFunction)
- {
- case kDETcmdInit:
- callBlockPtr->init.newCallFors = kDETCallForIdle + kDETCallForViewChanges;
- break;
-
- case kDETcmdIdle:
- case kDETcmdViewListChanged:
- err = DoIdle(callBlockPtr);
- break;
-
- }
- }
-
- return err;
- }
-
- static OSErr GetPropertyNumber(DETCallBlockPtr callBlockPtr, DETTargetSelector selector, long itemNumber, short property, long *value)
- {
- OSErr err;
- DETCallBackBlock cbb;
-
- cbb.getPropertyNumber.reqFunction = kDETcmdGetPropertyNumber;
- cbb.getPropertyNumber.property = property;
-
- cbb.getPropertyNumber.target.selector = selector;
- cbb.getPropertyNumber.target.aspectName = nil;
- cbb.getPropertyNumber.target.itemNumber = itemNumber;
-
- err = CallBackDET(callBlockPtr, &cbb);
-
- *value = cbb.getPropertyNumber.propertyValue;
-
- return err;
- }
-
- static OSErr GetNumSublistItems(DETCallBlockPtr callBlockPtr, long *num)
- {
- OSErr err;
- DETCallBackBlock cbb;
-
- cbb.sublistCount.reqFunction = kDETcmdSublistCount;
- cbb.sublistCount.target.selector = kDETSelf;
-
- err = CallBackDET(callBlockPtr, &cbb);
-
- *num = cbb.sublistCount.count;
-
- return err;
- }
-
- static OSErr SetPropertyNumber(DETCallBlockPtr callBlockPtr,
- short property,
- long newValue)
- {
- OSErr err;
- DETCallBackBlock cbb;
-
- cbb.setPropertyNumber.reqFunction = kDETcmdSetPropertyNumber;
- cbb.setPropertyNumber.property = property;
- cbb.setPropertyNumber.target.selector = kDETSelf;
- cbb.setPropertyNumber.newValue = newValue;
-
- err = CallBackDET(callBlockPtr, &cbb);
-
- return err;
- }
-
- static OSErr DoIdle(DETCallBlockPtr callBlockPtr)
- {
- OSErr err;
- long oldNumber, actualNumber;
-
- err = GetPropertyNumber(callBlockPtr, kDETSelf, 0, prNumTracks, &oldNumber);
-
- if (err == noErr)
- {
- err = GetNumSublistItems(callBlockPtr, &actualNumber);
- }
-
- if ((err == noErr) && (oldNumber != actualNumber))
- {
- err = SetPropertyNumber(callBlockPtr, prNumTracks, actualNumber);
- }
-
- if (err == noErr)
- {
- long index;
- long oldSeconds, actualSeconds = 0;
- long seconds;
- long minutes;
- long hours;
-
- // First add up the real playing time by asking each track for its playing time.
- for (index = 1; (err == noErr) && (index <= actualNumber); ++index)
- {
- err = GetPropertyNumber(callBlockPtr, kDETSublistItem, index, prTrackSeconds, &seconds);
-
- if (err == noErr)
- {
- err = GetPropertyNumber(callBlockPtr, kDETSublistItem, index, prTrackMinutes, &minutes);
- }
-
- if (err == noErr)
- {
- actualSeconds += (minutes * 60 + seconds);
- }
- }
-
- // Get the old total playing time.
- if (err == noErr)
- {
- err = GetPropertyNumber(callBlockPtr, kDETSelf, 0, prPlayingTimeHours, &hours);
- }
-
- if (err == noErr)
- {
- err = GetPropertyNumber(callBlockPtr, kDETSelf, 0, prPlayingTimeMinutes, &minutes);
- }
-
- if (err == noErr)
- {
- err = GetPropertyNumber(callBlockPtr, kDETSelf, 0, prPlayingTimeSeconds, &seconds);
- }
-
- // Now compare the two playing times and, if they're different, take the new one.
- if (err == noErr)
- {
- oldSeconds = 3600 * hours + 60 * minutes + seconds;
-
- if (oldSeconds != actualSeconds)
- {
- hours = actualSeconds / 3600;
- err = SetPropertyNumber(callBlockPtr, prPlayingTimeHours, hours);
-
- if (err == noErr)
- {
- actualSeconds -= (hours * 3600);
- minutes = actualSeconds / 60;
- err = SetPropertyNumber(callBlockPtr, prPlayingTimeMinutes, minutes);
- }
-
- if (err == noErr)
- {
- actualSeconds -= (minutes * 60);
- err = SetPropertyNumber(callBlockPtr, prPlayingTimeSeconds, actualSeconds);
- }
- }
- }
- }
-
- return err;
- }
-
-